
import requests
import os

from_id = 0
# 图片后缀
IMG_SUFFIX = '.png'

# 去哪儿
# IMG_URL = "http://qapi.qunar.com/api/captcha/getImage?device=1&level=7&k=9f992f90&source=tcdev&t=1577427462911"
# 山东航空
# IMG_URL = "http://sc.travelsky.com/scet/servlet/com.travelsky.web.scet.user.VerificationPicFactory"
# 支付宝
IMG_URL = "https://omeo.alipay.com/service/checkcode?sessionID=770c-849f-4556-b640-f1910233da85RZ41&amp;t=0.990658788115933"


SAVE_PAYH = '../model_type/zfb/label/old/'

def save_one_image():
    global from_id
    r = requests.get(IMG_URL)
    with open(SAVE_PAYH+ str(from_id) + IMG_SUFFIX, 'wb') as f:
        f.write(r.content)
    from_id = from_id + 1

def save_image(nums):
    if not os.path.exists(SAVE_PAYH):
        os.makedirs(SAVE_PAYH)

    for i in range(nums):
        save_one_image()
        if i%10 == 0:
            print("已经保存的图片数量：{}".format(from_id))

    print('保存完成')

if __name__ == '__main__':
    save_image(20)
